package com.ruoyi.book.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSONObject;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.http.HttpUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.book.domain.BookCommission;
import com.ruoyi.book.service.IBookCommissionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;

/**
 * 图书委托Controller
 * 
 * @author hd
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/book/commission")
@Api(tags = "图书委托管理")
public class BookCommissionController extends BaseController
{
    @Autowired(required=false)
    private IBookCommissionService bookCommissionService;

    /**
     * 查询图书委托列表
     */
    @ApiOperation("查询图书委托列表")
    // @PreAuthorize("@ss.hasPermi('book:commission:list')")
    @GetMapping("/list")
    public TableDataInfo list(BookCommission bookCommission,Integer pageNum,Integer pageSize)
    {
        if(pageNum!=null&&pageSize!=null){
            PageHelper.startPage(pageNum,pageSize);
        }else{
            startPage();
        }
        List<BookCommission> list = bookCommissionService.selectBookCommissionList(bookCommission);
        return getDataTable(list);
    }

    /**
     * 导出图书委托列表
     */
    @ApiOperation("导出图书委托列表")
    // @PreAuthorize("@ss.hasPermi('book:commission:export')")
    @Log(title = "图书委托", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BookCommission bookCommission)
    {
        List<BookCommission> list = bookCommissionService.selectBookCommissionList(bookCommission);
        ExcelUtil<BookCommission> util = new ExcelUtil<BookCommission>(BookCommission.class);
        util.exportExcel(response, list, "图书委托数据");
    }

    /**
     * 获取图书委托详细信息
     */
    @ApiOperation("获取图书委托详细信息")
    @ApiImplicitParam(name = "commissionId", value = "委托id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Integer.class)
    // @PreAuthorize("@ss.hasPermi('book:commission:query')")
    @GetMapping(value = "/{commissionId}")
    public AjaxResult getInfo(@PathVariable("commissionId") Long commissionId)
    {
        return success(bookCommissionService.selectBookCommissionByCommissionId(commissionId));
    }

    /**
     * 新增图书委托
     */
    @ApiOperation("新增图书委托")
    // @PreAuthorize("@ss.hasPermi('book:commission:add')")
    @Log(title = "图书委托", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BookCommission bookCommission)
    {
        return toAjax(bookCommissionService.insertBookCommission(bookCommission));
    }

    /**
     * 修改图书委托
     */
    @ApiOperation("修改图书委托")
    // @PreAuthorize("@ss.hasPermi('book:commission:edit')")
    @Log(title = "图书委托", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BookCommission bookCommission)
    {
        return toAjax(bookCommissionService.updateBookCommission(bookCommission));
    }

    /**
     * 删除图书委托
     */
    @ApiOperation("删除图书委托")
    @ApiImplicitParam(
            name = "commissionIds",
            value = "委托ID数组（多个ID用逗号分隔）",
            required = true,
            dataType = "array", // 明确指定为数组类型
            paramType = "path",
            // dataTypeClass = Long.class, // 指定数组元素的类型为 Long
            example = "1,2,3" // 提供一个示例值
    )
    // @PreAuthorize("@ss.hasPermi('book:commission:remove')")
    @Log(title = "图书委托", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commissionIds}")
    public AjaxResult remove(@PathVariable Long[] commissionIds)
    {
        return toAjax(bookCommissionService.deleteBookCommissionByCommissionIds(commissionIds));
    }

}
